<?php


namespace app\login\tool;



use app\common\controller\Base;
use think\Db;

/**
 * @title Judge
 * @description 接口说明
 * @group 接口分组
 * @author 韦贵杰
 * @date 2020/7/28
 */
class Judge
{
    protected $departmentManagement = array() ;

//    protected $deviceManagement = ['config'];
    protected $deviceManagement = array('Config');

    protected $attendanceManagement = array();

    protected $temperatureManagement = array();

    protected $workerManagement = array();

    protected $accessManagement = array();

    protected $formManagement =array();

    protected $access ;

    //传入token数据库中的数据
    public  function judge($id,$controller)
    {

//       $controller='Config';
//        dump($controller);
//        dump($this->deviceManagement);
//        $role = \app\login\model\Role::where('account_id',$id)->find();

        $role = Db::connect('mysql://root:admin@127.0.0.1:3306/zb_login')
            ->table('tp_role')
            ->where('account_id',$id)
            ->find();

        $this->access =false;

        if (in_array($controller, $this->formManagement)) {
            if ($role->form==1){
                $this->access =true;
            }
        }

        if (in_array($controller, $this->accessManagement)) {
            if ($role->access==1){
                $this->access =true;

            }
        }

        if (in_array($controller, $this->workerManagement)) {
            if ($role->worker==1){
                $this->access =true;

            }
        }

        if (in_array($controller, $this->temperatureManagement)) {
            if ($role->temp==1){
                $this->access =true;

            }
        }

        if (in_array($controller, $this->attendanceManagement)) {
            if ($role->attendance==1){
                $this->access =true;

            }
        }

        if (in_array($controller, $this->departmentManagement)) {
            if ($role->department==1){
                $this->access =true;

            }
        }

        if (in_array($controller, $this->deviceManagement)) {

            if ($role['device'] == 1){
                $this->access =true;
                return true;
            }
        }


        return  $this->access;

    }
}